Passed
Pull Request — master (#164)
by Mathieu
02:12
created

Billing1605707955778   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
A up 0 9 1
A down 0 9 1
1
import {MigrationInterface, QueryRunner} from "typeorm";
2
3
export class Billing1605707955778 implements MigrationInterface {
4
    name = 'Billing1605707955778'
5
6
    public async up(queryRunner: QueryRunner): Promise<void> {
7
        await queryRunner.query(`CREATE TABLE "billing_item" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "title" character varying NOT NULL, "quantity" integer NOT NULL, "amount" integer NOT NULL, "discount" integer DEFAULT 0, "billingId" uuid NOT NULL, CONSTRAINT "PK_cd7d33c1c91b479709adc5328b2" PRIMARY KEY ("id"))`);
8
        await queryRunner.query(`CREATE TYPE "billing_status_enum" AS ENUM('draft', 'sent', 'payed', 'canceled')`);
9
        await queryRunner.query(`CREATE TABLE "billing" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "status" "billing_status_enum" NOT NULL, "billingId" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "expiryDate" TIMESTAMP NOT NULL, "ownerId" uuid NOT NULL, "quoteId" uuid, "customerId" uuid NOT NULL, CONSTRAINT "UQ_8ff787c7772b6c47b251641a388" UNIQUE ("billingId"), CONSTRAINT "PK_d9043caf3033c11ed3d1b29f73c" PRIMARY KEY ("id"))`);
10
        await queryRunner.query(`ALTER TABLE "billing_item" ADD CONSTRAINT "FK_d198acc598a7a520998193ccd4c" FOREIGN KEY ("billingId") REFERENCES "billing"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
11
        await queryRunner.query(`ALTER TABLE "billing" ADD CONSTRAINT "FK_b93cd6c332ff301398aa97ab2b8" FOREIGN KEY ("ownerId") REFERENCES "user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
12
        await queryRunner.query(`ALTER TABLE "billing" ADD CONSTRAINT "FK_1354352a7fa5c63183607771552" FOREIGN KEY ("quoteId") REFERENCES "quote"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
13
        await queryRunner.query(`ALTER TABLE "billing" ADD CONSTRAINT "FK_578708a868391988c279cf8ee7b" FOREIGN KEY ("customerId") REFERENCES "customer"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
14
    }
15
16
    public async down(queryRunner: QueryRunner): Promise<void> {
17
        await queryRunner.query(`ALTER TABLE "billing" DROP CONSTRAINT "FK_578708a868391988c279cf8ee7b"`);
18
        await queryRunner.query(`ALTER TABLE "billing" DROP CONSTRAINT "FK_1354352a7fa5c63183607771552"`);
19
        await queryRunner.query(`ALTER TABLE "billing" DROP CONSTRAINT "FK_b93cd6c332ff301398aa97ab2b8"`);
20
        await queryRunner.query(`ALTER TABLE "billing_item" DROP CONSTRAINT "FK_d198acc598a7a520998193ccd4c"`);
21
        await queryRunner.query(`DROP TABLE "billing"`);
22
        await queryRunner.query(`DROP TYPE "billing_status_enum"`);
23
        await queryRunner.query(`DROP TABLE "billing_item"`);
24
    }
25
26
}
27